<template>
  <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="90px">
    <el-form-item label="运单编号" prop="shipmentCode">
      <el-input
        v-model="queryParams.shipmentCode"
        placeholder="请输入运单编号"
        clearable
        size="small"
        @keyup.enter.native="handleSearch"
      />
    </el-form-item>
    <el-form-item label="发货方" prop="senderId">
      <el-select v-model="queryParams.senderId" placeholder="请选择发货方" clearable size="small">
        <el-option
          v-for="sender in senderList"
          :key="sender.senderId"
          :label="sender.senderName"
          :value="sender.senderId"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="收货方" prop="receiverId">
      <el-select v-model="queryParams.receiverId" placeholder="请选择收货方" clearable size="small">
        <el-option
          v-for="receiver in receiverList"
          :key="receiver.receiverId"
          :label="receiver.receiverName"
          :value="receiver.receiverId"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="运单状态" prop="shipmentStatus">
      <el-select v-model="queryParams.shipmentStatus" placeholder="请选择运单状态" clearable size="small">
        <el-option label="待发货" value="1" />
        <el-option label="运输中" value="2" />
        <el-option label="已签收" value="3" />
        <el-option label="已取消" value="4" />
      </el-select>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-date-picker
        v-model="dateRange"
        size="small"
        style="width: 240px"
        value-format="yyyy-MM-dd"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearch">搜索</el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="handleReset">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'ShipmentSearchForm',
  props: {
    queryParams: {
      type: Object,
      required: true
    },
    senderList: {
      type: Array,
      default: () => []
    },
    receiverList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // 日期范围
      dateRange: []
    }
  },
  watch: {
    dateRange(val) {
      if (val) {
        this.queryParams.beginTime = val[0]
        this.queryParams.endTime = val[1]
      } else {
        this.queryParams.beginTime = undefined
        this.queryParams.endTime = undefined
      }
    }
  },
  methods: {
    /** 搜索按钮操作 */
    handleSearch() {
      this.$emit('search')
    },
    /** 重置按钮操作 */
    handleReset() {
      this.dateRange = []
      this.$refs.queryForm.resetFields()
      this.$emit('reset')
    }
  }
}
</script>